Repository navigation
[gremlin-python] [1/4] Add async HTTP streaming transport, AsyncResultSet, and GraphBinaryV4 stream reader - #3725
masterhugo wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3725 +/- ##
============================================
+ Coverage 76.35% 76.75% +0.39%
- Complexity 13424 14357 +933
============================================
Files 1012 1037 +25
Lines 60341 64819 +4478
Branches 7075 7704 +629
============================================
+ Hits 46076 49753 +3677
- Misses 11548 11967 +419
- Partials 2717 3099 +382 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
60886f4 to
a3381f0
Compare
|
Thanks for contributing @masterhugo and sorry for the delayed response. I'll be taking a look at your other 3.x version of this PR soon but I wanted to let you know that the approach you are taking here probably isn't the right direction. 4.x is the next major release and we would probably need to come a decision on what async APIs look like in TinkerPop (this affects |
|
Just to clarify a few things from my earlier post. While I think the changes made in your 3.x PR work for 3.x, I don't think they are the right decisions for 4.x given that we can take a more holistic approach with async since breaking changes are allowed in the Getting async to work natively in the |
|
Thanks for clarifying @kenhuuu! Initially I took this approach mainly to avoid breaking what was already in master, but if breaking changes are on the table for 4.x, I'd definitely prefer to build something natively async from scratch and move away from the sync layer in the driver altogether. I already have an open [DISCUSS] thread on the dev list from when I started working on TINKERPOP-2774: https://lists.apache.org/thread/wm5d9hnx5jkt8mgzqg4g8vtplhohrh3n We can continue the discussion there (or I can post a follow-up in that thread) to figure out the best way to design and implement a fully native async driver from the ground up for 4.x. |
Summary (Part 1 of 4: Native
asyncioforgremlin-python4.0)This is PR 1 of 4 introducing native
asynciosupport togremlin-pythonfor TinkerPop 4.0 over HTTP streaming, withoutnest_asyncio, backgroundThreadPoolExecutorpools, or per-connection private event loops (asyncio.new_event_loop()).Why native
asynciowithoutnest_asyncio?Currently,
AiohttpHTTPTransportcreates a private event loop per connection and drivesaiohttpsynchronously viarun_until_complete(). When called from inside an already-running event loop (FastAPI/uvloop, Jupyter notebooks, async AWS Lambda handlers), it fails withRuntimeError: Cannot run the event loop while another loop is running, andnest_asynciocannot patch Cython-based loops likeuvloop.What is included in PR 1 (Foundation layer)
gremlin_python/driver/aiohttp/async_transport.py:AsyncBufferedStream: sliding-windowbytearraybuffer overaiohttp.ClientResponse.contentwithcheckpoint(),restore(),compact(),fill_more(), andread_exactly(). Translatesaiohttp.ServerTimeoutErrorintoReadTimeoutError.AsyncAiohttpHTTPTransport: nativeaiohttp.ClientSessiontransport bound directly toasyncio.get_running_loop().gremlin_python/driver/async_resultset.py:AsyncResultSet: single-item streaming result set supportingawait rs.one()(returning_EXHAUSTEDon stream end soNoneresult items are preserved),await rs.all(), andasync for item in rs, usingasyncio.wait(..., return_when=FIRST_COMPLETED)instead of polling loops.gremlin_python/driver/serializer.py:GraphBinarySerializersV4.deserialize_async_response_stream(stream)to incrementally decode GraphBinary v4 (0x84) objects and end-of-stream trailers across arbitrary HTTP chunk boundaries.tests/unit/driver/test_async_http_streaming.py:AsyncResultSet,AsyncBufferedStream,deserialize_async_response_stream(including 2-byte chunk fragmentation across object/trailer boundaries), andAsyncAiohttpHTTPTransport.Roadmap of the 4-PR Series
AsyncBufferedStream,AsyncAiohttpHTTPTransport,AsyncResultSet,deserialize_async_response_streamAsyncConnection&AsyncClient(asyncio.Queueconnection pool)AsyncDriverRemoteConnection&AsyncGraphTraversal(async_traversal())AsyncTransaction(g.tx(),execute_in_tx), integration tests, examples, and documentation